home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqdisplay / surface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-16  |  12.9 KB  |  343 lines

  1. #define    LIBQDISPLAY_CORE
  2. #define    LIBQTOOLS_CORE
  3. #define    LIBQBUILD_CORE
  4. #include "../include/libqdisplay.h"
  5.  
  6. /* lightmap related */
  7. static int row, lightmapWidth, step, shift;
  8. static int *lightmapIndex;
  9.  
  10. #ifdef    DRIVER_8BIT
  11. #include "surface8.c"
  12. #endif
  13. #ifdef    DRIVER_16BIT
  14. #include "surface16.c"
  15. #endif
  16. #ifdef    DRIVER_24BIT
  17. #include "surface24.c"
  18. #endif
  19. #ifdef    DRIVER_32BIT
  20. #endif
  21.  
  22. short int lightstyleStrings[16][64] =
  23. {
  24.   /* 0 normal */
  25.   /* "m", */
  26.   {12 * 22 >> 2},
  27.  
  28.   /* 1 FLICKER (first variety) */
  29.   /* "mmnmmommommnonmmonqnmmo", */
  30.   {12 * 22 >> 2, 12 * 22 >> 2, 13 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 13 * 22 >> 2, 14 * 22 >> 2,
  31.    13 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2, 13 * 22 >> 2, 16 * 22 >> 2, 13 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2},
  32.  
  33.   /* 2 SLOW STRONG PULSE */
  34.   /* "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba", */
  35.   {0 * 22 >> 2, 1 * 22 >> 2, 2 * 22 >> 2, 3 * 22 >> 2, 4 * 22 >> 2, 5 * 22 >> 2, 6 * 22 >> 2, 7 * 22 >> 2, 8 * 22 >> 2, 9 * 22 >> 2, 10 * 22 >> 2, 11 * 22 >> 2, 12 * 22 >> 2, 13 * 22 >> 2, 14 * 22 >> 2,
  36.    15 * 22 >> 2, 16 * 22 >> 2, 17 * 22 >> 2, 18 * 22 >> 2, 19 * 22 >> 2, 20 * 22 >> 2, 21 * 22 >> 2, 22 * 22 >> 2, 23 * 22 >> 2, 24 * 22 >> 2, 25 * 22 >> 2, 24 * 22 >> 2, 23 * 22 >> 2,
  37.    22 * 22 >> 2, 21 * 22 >> 2, 20 * 22 >> 2, 19 * 22 >> 2, 18 * 22 >> 2, 17 * 22 >> 2, 16 * 22 >> 2, 15 * 22 >> 2, 14 * 22 >> 2, 13 * 22 >> 2, 12 * 22 >> 2, 11 * 22 >> 2, 10 * 22 >> 2,
  38.    9 * 22 >> 2, 8 * 22 >> 2, 7 * 22 >> 2, 6 * 22 >> 2, 5 * 22 >> 2, 4 * 22 >> 2, 3 * 22 >> 2, 2 * 22 >> 2, 1 * 22 >> 2, 0 * 22 >> 2},
  39.  
  40.   /* 3 CANDLE (first variety) */
  41.   /* "mmmmmaaaaammmmmaaaaaabcdefgabcdefg", */
  42.   {12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2,
  43.    12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 01 * 22 >> 2, 02 * 22 >> 2, 03 * 22 >> 2, 04 * 22 >> 2, 05 * 22 >> 2,
  44.    06 * 22 >> 2, 00 * 22 >> 2, 01 * 22 >> 2, 02 * 22 >> 2, 03 * 22 >> 2, 04 * 22 >> 2, 05 * 22 >> 2, 06 * 22 >> 2},
  45.  
  46.   /* 4 FAST STROBE */
  47.   /* "mamamamamama", */
  48.   {12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2},
  49.  
  50.   /* 5 GENTLE PULSE 1 */
  51.   /* "jklmnopqrstuvwxyzyxwvutsrqponmlkj", */
  52.   {9 * 22 >> 2, 10 * 22 >> 2, 11 * 22 >> 2, 12 * 22 >> 2, 13 * 22 >> 2, 14 * 22 >> 2, 15 * 22 >> 2, 16 * 22 >> 2, 17 * 22 >> 2, 18 * 22 >> 2, 19 * 22 >> 2, 20 * 22 >> 2, 21 * 22 >> 2, 22 * 22 >> 2,
  53.    23 * 22 >> 2, 24 * 22 >> 2, 25 * 22 >> 2, 24 * 22 >> 2, 23 * 22 >> 2, 22 * 22 >> 2, 21 * 22 >> 2, 20 * 22 >> 2, 19 * 22 >> 2, 18 * 22 >> 2, 17 * 22 >> 2, 16 * 22 >> 2, 15 * 22 >> 2, 14 * 22 >> 2,
  54.    13 * 22 >> 2, 12 * 22 >> 2, 11 * 22 >> 2, 10 * 22 >> 2, 9 * 22 >> 2},
  55.  
  56.   /* 6 FLICKER (second variety) */
  57.   /* "nmonqnmomnmomomno", */
  58.   {13 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2, 13 * 22 >> 2, 16 * 22 >> 2, 13 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2, 12 * 22 >> 2, 13 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2, 12 * 22 >> 2, 14 * 22 >> 2,
  59.    12 * 22 >> 2, 13 * 22 >> 2, 14 * 22 >> 2},
  60.  
  61.   /* 7 CANDLE (second variety) */
  62.   /* "mmmaaaabcdefgmmmmaaaammmaamm", */
  63.   {12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 01 * 22 >> 2, 02 * 22 >> 2, 03 * 22 >> 2, 04 * 22 >> 2, 05 * 22 >> 2, 06 * 22 >> 2, 12 * 22 >> 2,
  64.    12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2},
  65.  
  66.   /* 8 CANDLE (third variety) */
  67.   /* "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa", */
  68.   {12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2,
  69.    12 * 22 >> 2, 00 * 22 >> 2, 01 * 22 >> 2, 02 * 22 >> 2, 03 * 22 >> 2, 04 * 22 >> 2, 05 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2,
  70.    12 * 22 >> 2, 00 * 22 >> 2, 01 * 22 >> 2, 02 * 22 >> 2, 03 * 22 >> 2, 04 * 22 >> 2, 05 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2},
  71.  
  72.   /* 9 SLOW STROBE (fourth variety) */
  73.   /* "aaaaaaaazzzzzzzz", */
  74.   {00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 25 * 22 >> 2, 25 * 22 >> 2, 25 * 22 >> 2, 25 * 22 >> 2, 25 * 22 >> 2, 25 * 22 >> 2,
  75.    25 * 22 >> 2, 25 * 22 >> 2},
  76.  
  77.   /* 10 FLUORESCENT FLICKER */
  78.   /* "mmamammmmammamamaaamammma", */
  79.   {12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2,
  80.    00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 12 * 22 >> 2, 00 * 22 >> 2},
  81.  
  82.   /* 11 SLOW PULSE NOT FADE TO BLACK */
  83.   /* "abcdefghijklmnopqrrqponmlkjihgfedcba" */
  84.   {0 * 22 >> 2, 1 * 22 >> 2, 2 * 22 >> 2, 3 * 22 >> 2, 4 * 22 >> 2, 5 * 22 >> 2, 6 * 22 >> 2, 7 * 22 >> 2, 8 * 22 >> 2, 9 * 22 >> 2, 10 * 22 >> 2, 11 * 22 >> 2, 12 * 22 >> 2, 13 * 22 >> 2, 14 * 22 >> 2, 15 * 22 >> 2,
  85.    16 * 22 >> 2, 17 * 22 >> 2, 17 * 22 >> 2, 16 * 22 >> 2, 15 * 22 >> 2, 14 * 22 >> 2, 13 * 22 >> 2, 12 * 22 >> 2, 11 * 22 >> 2, 10 * 22 >> 2, 9 * 22 >> 2, 8 * 22 >> 2, 7 * 22 >> 2, 6 * 22 >> 2, 5 * 22 >> 2,
  86.    4 * 22 >> 2, 3 * 22 >> 2, 2 * 22 >> 2, 1 * 22 >> 2, 0 * 22 >> 2}
  87. };
  88.  
  89. int lightstyleLengths[11] =
  90. {
  91.   1, 23, 51, 33, 12, 17, 28, 42, 16, 25, 36
  92. };
  93.  
  94. /*
  95.  * void UpdateDisplayII(void *oldBuffer, short int x, short int y, short int width, short int height) {
  96.  * int spanCount, spanSize;
  97.  * unsigned short int *spanOut = localDim.frameBuffer;
  98.  * unsigned short int *spanIn = oldBuffer;
  99.  * 
  100.  * spanOut += (y * localDim.Width) + (x);
  101.  * 
  102.  * if((width + x) > localDim.Width)
  103.  * spanSize = localDim.Width - x;
  104.  * else
  105.  * spanSize = width;
  106.  * 
  107.  * if((height + y) > localDim.Height)
  108.  * spanCount = localDim.Height - y;
  109.  * else
  110.  * spanCount = height;
  111.  * 
  112.  * for(; spanCount >= 0; spanCount--, spanOut += localDim.Width, spanIn += width)
  113.  * memcpy(spanOut, spanIn, spanSize);
  114.  * 
  115.  * SwapDisplay(localDim.frameBuffer);
  116.  * }    
  117.  */
  118.  
  119. void GetTMap(__memBase, struct texture *Text, short int mip)
  120. {
  121.   int i, j, x, y, x0, rows, lines;
  122.   unsigned char *lightmap;
  123.   int *lightindex;
  124.   struct fastmipmap *fastMM;
  125.   displaypointer data;
  126.  
  127.   fastMM = &Text->mipMaps[mip];
  128.   textureType = Text->textureType;
  129.   textureColor = Text->textureColor;
  130.   
  131.   /* flat or wire dont need texture-informations */
  132.   if(displayType != DISPLAY_TEXTURED)
  133.     return;
  134.  
  135.   /* skies have no lighting infos, and are not mipmapped */
  136.   if (Text->textureType == SKY_TYPE) {
  137.     rows = Text->mipMaps[MIPMAP_0].rawBody.width;
  138.     if (Text->mipMaps[MIPMAP_0].newBody.width == rows) {
  139.       Text->mipMaps[MIPMAP_0].newBody.width = ~rows;        /* identifier for first converted face-sky */
  140. #ifdef    DRIVER_8BIT
  141.       if (localDim.frameDepth <= 8)
  142.     BuildSky8(Text->tiled, Text->mipMaps[MIPMAP_0].rawBody.data);
  143.       else
  144. #endif
  145. #ifdef    DRIVER_16BIT
  146.       if (localDim.frameDepth <= 16)
  147.     BuildSky16(Text->tiled, Text->mipMaps[MIPMAP_0].rawBody.data);
  148.       else
  149. #endif
  150. #ifdef    DRIVER_24BIT
  151.       if (localDim.frameDepth <= 24)
  152.     BuildSky24(Text->tiled, Text->mipMaps[MIPMAP_0].rawBody.data);
  153.       else
  154. #endif
  155. #ifdef    DRIVER_32BIT
  156. #endif
  157.     ;
  158.     }
  159.     Text->texChanged = FALSE;
  160.   }
  161.   /* non-walls can have lighting info, but no special properties in size */
  162.   else if (Text->textureType != WALL_TYPE) {
  163.     rows = fastMM->rawBody.width;
  164.     lines = fastMM->rawBody.height;
  165.     textureMask1 = ((rows - 1) << WARP_SHIFT) >> mip;
  166.     textureMask2 = (rows - 1) >> mip;
  167.     textureShift1 = 16 - WARP_SHIFT + mip;
  168.     textureShift2 = 16 - mip;
  169.  
  170. #ifdef    DRIVER_8BIT
  171. #ifdef    FAST_WARP
  172.     swim_u = swim_um[mip];
  173.     swim_v = swim_vm[mip];
  174. #endif
  175.     if (textureType == WATER_TYPE)
  176.       preTransparency = waterTransparency;            /* 50 */
  177.     else if (textureType == SLIME_TYPE)
  178.       preTransparency = slimeTransparency;            /* 75 */
  179.     else
  180.       preTransparency = lavaTransparency;            /* 90 */
  181. #endif
  182.   }
  183.   /* walls are the most complex */
  184.   else {
  185.     rows = fastMM->newBody.width;
  186.     lines = fastMM->newBody.height;
  187.   }
  188.   textureRow = rows;
  189.  
  190. #ifdef    DRIVER_8BIT
  191.   if (localDim.frameDepth <= 8)
  192.     texture.indexed = data.indexed = (unsigned char *)Text->tiled;
  193.   else
  194. #endif
  195. #ifdef    DRIVER_16BIT
  196.   if (localDim.frameDepth <= 16)
  197.     texture.hicolor = data.hicolor = (unsigned short int *)Text->tiled;
  198.   else
  199. #endif
  200. #ifdef    DRIVER_24BIT
  201.   if (localDim.frameDepth <= 24)
  202.     texture.truecolor = data.truecolor = (struct rgb *)Text->tiled;
  203.   else
  204. #endif
  205. #ifdef    DRIVER_32BIT
  206. #endif
  207.     ;
  208.  
  209.   if (Text->texChanged) {
  210.     Text->texChanged = FALSE;
  211.  
  212.     step = fastMM->step;
  213.     shift = fastMM->shift;
  214.     row = fastMM->row;
  215.  
  216.     y = fastMM->y;
  217.     x0 = fastMM->x0;
  218.  
  219.     /* this could be if we have no lightinformation, or if the face emits no light */
  220.     if (!(lightmap = Text->lightdata)) {
  221. #ifdef    DRIVER_8BIT
  222.       if (localDim.frameDepth <= 8) {
  223.     if ((bspMem->shared.quake1.lightdatasize) && (textureType == WALL_TYPE))
  224.       brightColormap = &cachedColormap[0x0003D00];        /* standard ambient */
  225.     else
  226.       brightColormap = &cachedColormap[0x0001F00];        /* full bright (no lights), for waters etc. and if no lightinfo */
  227.       }
  228.       else
  229. #endif
  230. #if defined(DRIVER_16BIT) || defined(DRIVER_24BIT) || defined(DRIVER_32BIT)
  231.       {
  232.     if ((bspMem->shared.quake1.lightdatasize) && (textureType == WALL_TYPE))
  233.       brightColorshift = 1;                    /* standard ambient */
  234.     else
  235.       brightColorshift = 0;                    /* full bright (no lights), for waters etc. and if no lightinfo */
  236.       }
  237. #endif
  238.       ;
  239.  
  240.       for (j = 0; j < lines; j += step) {
  241.     x = x0;
  242.     for (i = 0; i < rows; i += step) {
  243. #ifdef    DRIVER_8BIT
  244.       if (localDim.frameDepth <= 8)
  245.         BuildBrightBlock8((data.indexed + lookup(j, rows) + i), &fastMM->rawBody, x, y);
  246.       else
  247. #endif
  248. #ifdef    DRIVER_16BIT
  249.       if (localDim.frameDepth <= 16)
  250.         BuildBrightBlock16((data.hicolor + lookup(j, rows) + i), &fastMM->rawBody, x, y);
  251.       else
  252. #endif
  253. #ifdef    DRIVER_24BIT
  254.       if (localDim.frameDepth <= 24)
  255.         BuildBrightBlock24((data.truecolor + lookup(j, rows) + i), &fastMM->rawBody, x, y);
  256.       else
  257. #endif
  258. #ifdef    DRIVER_32BIT
  259. #endif
  260.         ;
  261.       x += step;
  262.       if (x >= fastMM->rawBody.width)
  263.         x -= fastMM->rawBody.width;
  264.     }
  265.     y += step;
  266.     if (y >= fastMM->rawBody.height)
  267.       y -= fastMM->rawBody.height;
  268.       }
  269.     }
  270.     else {
  271.       /*
  272.        * so, we need a framecounter, the lights state is "lightstate = lighttable[lightstyle][framecounter % strlen(lighttable[lightstyle])]"
  273.        * lighttable is an array into the lightstyle-strings
  274.        * we have 26 different chars (a - z), a is total darkness and z is maxbright, m (12) is fullbright
  275.        * we need a double calculated as "(lightstate - 'a') / 12.0" (0.0-2.16) or as "(lightstate - 'a') * 21.25"
  276.        * normal brightness is 0x1F, so "0x1F * 0.0 = 0" and "0x1F * 2.16 ~= 0x3F"
  277.        */
  278.       lightmapWidth = Text->lightmap.width;
  279.       lightmapIndex = (int *)Text->lightmap.data;
  280.       memset(lightmapIndex, 0, Text->lightmap.size * sizeof(int));
  281.  
  282.       for (j = 0; (j < MAXLIGHTMAPS); j++) {            /* max 4 */
  283.     int lightState;
  284.     short int *lightStyle;
  285.  
  286.     if (!(lightStyle = Text->lightSString[j]))
  287.       break;
  288.     if (Text->lightSLength[j] > 1)                /* dynamic texture changing, next frame must also be processed by this routine */
  289.       Text->texChanged = TRUE;                /* if the string is only one pattern long, there is no changing from frame to frame */
  290.  
  291.     lightState = lightStyle[frameCounter % Text->lightSLength[j]];
  292.     lightindex = lightmapIndex;
  293.  
  294.     for (i = 0; i < Text->lightmap.size; i++)
  295.       *lightindex++ += (*lightmap++ * lightState);        /* all the light-styles */
  296.       }
  297.  
  298.       lightindex = lightmapIndex;
  299.       for (i = 0; i < Text->lightmap.size; i++) {        /* over- and underflow-correction */
  300.     int sum = *lightindex + (10 << 6);            /* ambient light */
  301.  
  302.     if (sum > (255 << 6))                    /* 64 = 1<<6 light-values */
  303.       sum = (255 << 6);
  304.     else if (sum < (0 << 6))
  305.       sum = (0 << 6);
  306.  
  307.     *lightindex++ = sum;
  308.       }
  309.  
  310.       for (j = 0; j < lines; j += step) {
  311.     x = x0;
  312.     for (i = 0; i < rows; i += step, ++lightmapIndex) {
  313. #ifdef    DRIVER_8BIT
  314.       if (localDim.frameDepth <= 8)
  315.         BuildLightBlock8((data.indexed + lookup(j, rows) + i), &fastMM->rawBody, x, y);
  316.       else
  317. #endif
  318. #ifdef    DRIVER_16BIT
  319.       if (localDim.frameDepth <= 16)
  320.         BuildLightBlock16((data.hicolor + lookup(j, rows) + i), &fastMM->rawBody, x, y);
  321.       else
  322. #endif
  323. #ifdef    DRIVER_24BIT
  324.       if (localDim.frameDepth <= 24)
  325.         BuildLightBlock24((data.truecolor + lookup(j, rows) + i), &fastMM->rawBody, x, y);
  326.       else
  327. #endif
  328. #ifdef    DRIVER_32BIT
  329. #endif
  330.         ;
  331.       x += step;
  332.       if (x >= fastMM->rawBody.width)
  333.         x -= fastMM->rawBody.width;
  334.     }
  335.     ++lightmapIndex;
  336.     y += step;
  337.     if (y >= fastMM->rawBody.height)
  338.       y -= fastMM->rawBody.height;
  339.       }
  340.     }
  341.   }
  342. }
  343.